<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul>li:nth-child(2) {
      color: red;
    }

    /* 倒数第几个 */
    ul>li:nth-last-child(5) {
      color: red;
    }

    ul>li:nth-last-child(-n+3) {
      color: yellow;
    }
  </style>
</head>

<body>

  <ul>
    <li>列表元素1</li>
    <li>列表元素2</li>
    <li>列表元素3</li>
    <li>列表元素4</li>
    <li>列表元素5</li>
    <li>列表元素6</li>
    <li>列表元素7</li>
    <li>列表元素8</li>
  </ul>
</body>

</html>